package service

import (
	"goweb/db"
	. "goweb/models"
)

type OrderService struct {
	OrderDb db.OrdeDb
}

//查询所有
func (o *OrderService) FindOrders() ([]DemoOrder, error) {

	orders, err := o.OrderDb.FindOrders()

	return orders, err
}

//根据orderNo查询
func (o *OrderService) FindOrderByOrderNo(orderNo string) (DemoOrder, error) {

	order, err := o.OrderDb.FindOrderByOrderNo(orderNo)

	return order, err
}

//添加
func (o *OrderService) AddOrder(order DemoOrder) error {
	err := o.OrderDb.AddOrder(order)

	return err
}

//根据userName模糊查询
func (o *OrderService) FindOrderByLikeUserName(userName string) ([]DemoOrder, error) {
	order, err := o.OrderDb.FindOrderByLikeUserName(userName)

	return order, err
}

//更新
func (o *OrderService) UpdateOrder(order DemoOrder) error {
	err := o.OrderDb.UpdateOrder(order)

	return err
}

//根据创建时间及金额进行排序
func (o *OrderService) FindOrderOrderByCreatedAtAndAmount() ([]DemoOrder, error) {
	orders, err := o.OrderDb.FindOrderOrderByCreatedAtAndAmount()

	return orders, err
}

//保存文件路径
func (o *OrderService) SaveFile(fileUrl string, id int) {
	o.OrderDb.SaveFileUrl(fileUrl, id)
}

//根据id查询
func (o *OrderService) FindOrderById(id int) (DemoOrder, error) {
	order, err := o.OrderDb.FindOrderById(id)

	return order, err
}
